/**
 * @Description：QuestionService接口的实现
 * @author： 20155872 游宇
 * @createTime: 2018-05-10 11:39
 **/

package com.campus_information_portal.service.impl;

import com.campus_information_portal.dao.QuestionDao;
import com.campus_information_portal.entity.Question;
import com.campus_information_portal.service.QuestionService;
import com.campus_information_portal.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @className: QuestionImpl
 * @Description: QuestionService接口的实现
 * @author: 20155872 游宇
 * @createTime: 2018-05-10 11:39
 **/
@Service
public class QuestionImpl implements QuestionService {
    @Autowired
    private QuestionDao questionDao;

    /**
     * @Description: 添加一条评价问题记录
     * @author: 20155872 游宇
     * @methodName: addQuestion
     * @param: Question question
     * @returnType: Msg<Question>
     * @createTime: 2018-05-10 11:39
     **/
    public Msg addQuestion(Question question) {
        if (questionDao.addQuestion(question)){
             return Msg.addData(1,"评价问题发布成功!");
        }
        return Msg.fail();
    }


    /**
     * @Description: 更新评价问题表中的一条记录
     * @author: 20155872 游宇
     * @methodName: updateQuestion
     * @param: Question question
     * @returnType: Msg<Question>
     * @createTime: 2018-05-10 11:39
     **/
    @Override
    public Msg updateQuestion(Question question) {
        if (questionDao.updateQuestion(question)){
             return Msg.addData(1,"评价问题更新成功!");
        }
        return Msg.fail();
    }

    /**
     * @Description: 根据questionid来获取一条记录
     * @author: 20155872 游宇
     * @methodName: getQuestion
     * @param: int questionId
     * @returnType: Msg<Question>
     * @createTime: 2018/5/13 10:27
     **/
    @Override
    public Msg getQuestion(int questionId) {
        Question question=questionDao.getQuestion(questionId);
        if (question!=null){
            return Msg.addData(100,"获取question记录成功",question);
        }
        return Msg.fail();
    }

    /**
     * @Description: 查询所有的评价问题记录
     * @author: 20155872 游宇
     * @methodName: findAllQuestion
     * @param: null
     * @returnType: Msg<Question>
     * @createTime: 2018/5/13 10:28
     **/
    @Override
    public Msg findAllQuestion() {
        List<Question> questionList=questionDao.findAllQuestion();
        if (questionList.size()!=0){

            return Msg.addData(100,"获取所有的评家问题记录成功",questionList);
        }
        return Msg.fail();
    }
    /**
     * @Description: 根据学期id来查询评价问题记录
     * @author: 20155872 游宇
     * @methodName: findQuestionByTermid
     * @param: int term_id 学期记录id
     * @returnType: Question
     * @createTime: 2018/5/13 10:28
     **/
    @Override
    public Msg findQuestionByTermid(int term_id) {
        Question question=questionDao.findQuestionByTermid(term_id);
        if(question!=null){
            return Msg.addData(1,"根据学期id获取评价问题记录成功",question);
        }
        return Msg.fail();
    }

    /**
     * @Description: 清空评价问题记录表
     * @author: 20155872 游宇
     * @methodName: deleteAllQuestion
     * @param: null
     * @returnType: boolean
     * @createTime: 2018/5/13 10:28
     **/
    @Override
    public Msg deleteAllQuestion() {
        if(questionDao.deleteAllQuestion()){
            return Msg.addData(1,"清空所有的评价问题成功！");
        }
        return Msg.fail();
    }

    /**
     * @Description: 根据评价问题记录id来删除评价问题记录
     * @author: 20155872 游宇
     * @methodName: deleteQuestionByQuestion_id
     * @param: int question_id
     * @returnType: boolean
     * @createTime: 2018/5/13 10:28
     **/
    @Override
    public Msg deleteQuestionByQuestion_id(int question_id) {
        if (questionDao.deleteQuestionByQuestion_id(question_id)){
            return Msg.addData(1,"已成功删除该条评价问题记录！");
        }
        return Msg.fail();
    }

}
